package com.link510.aitools.data;

import com.link510.aitools.core.data.CWMRetrofit;
import com.link510.aitools.core.data.model.QiniuFileListingModel;
import com.link510.aitools.core.data.restapi.AirobotService;
import com.link510.aitools.core.message.MessageInfo;

import io.reactivex.Completable;
import io.reactivex.Observable;

/**
 * 智能机器人
 */
public class AirobotDtata {

    private static AirobotDtata mInstance = null;

    /**
     * 智能机器人
     */
    private AirobotService airobotService = null;

    /**
     * 单例
     *
     * @return EnvironData
     */
    public synchronized static AirobotDtata getInstance() {

        if (mInstance == null) {
            synchronized (AirobotDtata.class) {

                if (mInstance != null) {
                    return mInstance;
                }

                mInstance = new AirobotDtata();
            }
        }

        return mInstance;
    }

    /**
     * 默认构造方法
     */
    private AirobotDtata() {
        airobotService = CWMRetrofit.instance().create(AirobotService.class);
    }


    //region

    /**
     * 修改设备编号
     *
     * @param deviceSN 设备编号
     * @param name     设备名称
     */
    public Observable<MessageInfo<String>> editName(String deviceSN,
                                                    String name) {

        return airobotService.editName(deviceSN, name);
    }

    /**
     * 修改设备编号
     *
     * @param deviceSN 设备编号
     * @param ip       设备IP
     * @param port     设备端口
     */
    public Observable<MessageInfo<String>> editIpAndPort(String deviceSN,
                                                         String ip,
                                                         Integer port) {
        return airobotService.editIpAndPort(deviceSN, ip, port);
    }


    /**
     * 固件更新
     *
     * @param deviceSN 设备编号
     * @param httpUrl  固件地址
     */
    public Observable<MessageInfo<String>> coreUpgradeSend(String deviceSN, String httpUrl) {
        return airobotService.coreUpgradeSend(deviceSN, httpUrl);
    }


    /**
     * 日志收集
     *
     * @param deviceSN 设备编号
     */
    public Observable<MessageInfo<String>> logsGet(String deviceSN)  {
        return airobotService.logsGet(deviceSN);
    }

    /**
     * 重启设备
     *
     * @param deviceSN 设备编号
     */
    public Observable<MessageInfo<String>> reboot(String deviceSN) {
        return airobotService.reboot(deviceSN);
    }

    //endregion

    //region LED

    /**
     * led文本下发
     *
     * @param deviceSN 设备编号
     * @param text     下发文本
     * @return 返回信息
     */
    public Observable<MessageInfo<String>> ledEditText(String deviceSN, String text) {
        return airobotService.ledEditText(deviceSN, text);
    }

    //endregion

    //region 图片或文件

    /**
     * 获取图片
     *
     * @param deviceSN 设备编号
     * @param time     时间戳
     * @param marker   maker
     * @param limit    长度
     * @return Observable<MessageInfo < QiniuFileListingModel>>
     */
    public Observable<MessageInfo<QiniuFileListingModel>> pictureList(String deviceSN,
                                                                      Integer time,
                                                                      String marker,
                                                                      Integer limit) {
        return airobotService.pictureList(deviceSN, time, marker, limit);
    }

    /**
     * 获取图片
     *
     * @param bucket 空间
     * @return Observable<MessageInfo < QiniuFileListingModel>>
     */
    public Observable<MessageInfo<String>> getUploadToken(String bucket) {
        return airobotService.getUploadToken(bucket);
    }


    //endregion


    //region 音频模块

    /**
     * 音频下发中
     *
     * @param deviceSN 设备编码
     * @param mp3Url   mp3URL地址
     */
    public Observable<MessageInfo<String>> audioEditUrl(String deviceSN, String mp3Url) {
        return airobotService.audioEditUrl(deviceSN, mp3Url);
    }

    /**
     * 远程喊话
     *
     * @param deviceSN 设备编码
     * @param mp3Url   mp3地址
     */
    public Observable<MessageInfo<String>> audioShoutingUrl(String deviceSN, String mp3Url) {
        return airobotService.audioShoutingUrl(deviceSN, mp3Url);
    }

    //endregion

}
